
#include <BLibrary>
#include "member_BLibrary.h"

using namespace BWE;

#define member					(*(member_BLibrary*)_ptr)
#define member_allocate()		_ptr = new member_BLibrary
#define member_release()		delete (member_BLibrary*)_ptr

BLibrary::BLibrary()
{
	member_allocate();
}
BLibrary::BLibrary(const BString& fileName)
{
	member_allocate();
	member.fileName = fileName;
}
BLibrary::~BLibrary()
{
	member.unload();
	member_release();
}

void BLibrary::setFileName(const BString& fileName)
{
	if(member.fileName != fileName)
	{
		member.unload();
		member.fileName = fileName;
	}
}
const BString& BLibrary::fileName() const
{
	return member.fileName;
}

bool BLibrary::load()
{
	member.load();
	return isLoaded();
}
bool BLibrary::load(const BString& libName)
{
	member.unload();
	member.fileName = libName;
	return load();
}
bool BLibrary::unload()
{
	return member.unload();
}

bool BLibrary::isLoaded()
{
	return member.handle != 0;
}

void* BLibrary::get(const BString& slotName)
{
	if(slotName.empty())
		return 0;
	return member.address(slotName.cstr());
}

